package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Person;
import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
   private static Person[] stuArr=new Student[5];

    public boolean AddStudent(Person person) {
        int  index=-1;
        //判断数组里面是否存在数据
        for (int i = 0; i < stuArr.length; i++) {
            Person student=stuArr[i];
            if(student==null){
                index=i;
                break;
            }
        }
        if (index==-1){
            //System.out.println("装满了");
            return  false;
        }else{
            stuArr[index]=person;
            return  true;
        }
    }

    public Person[] findAllStudent() {
        return stuArr;
    }

    public void updateStudent(String id, Person newStu) {
        for (int i = 0; i < stuArr.length; i++) {
            Person p=stuArr[i];
            if(p!=null&&p.getId().equals(id)){
            p.setName(newStu.getName());
            p.setAge(newStu.getAge());
            p.setBirthday(newStu.getBirthday());
            }
        }
    }

    public void deleteStudent(String id) {
        for (int i = 0; i < stuArr.length; i++) {
            Person p=stuArr[i];
            if(p!=null&&p.getId().equals(id)){
           stuArr[i]=null;
            }
        }
    }
}
